Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mic_privacy: initial implementation #9788

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mbukowsk
Copy link
Contributor

Audio privacy feature allows end user to directly
control if user space applications receive actual
data from input devices (microphones). The control
is bypassing application level settings or operating
system controls (like audio endpoint volume).

src/audio/base_fw.c Outdated Show resolved Hide resolved
IPC4_UAOL_CAPS_HW_CFG = 10
IPC4_UAOL_CAPS_HW_CFG = 10,
/* Mic privacy capabilities */
IPC4_PRIVACY_CAPS_HW_CFG = 11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would re-name these to be more specific to:
IPC4_INTEL_MIC_PRIVACY_CAPS_HW_CFG (and IPC4_INTEL_UAOL_CAPS_HW_CFG).

it looks to me that we are passing the raw content of the DfMICPVCP register, which is pretty much Intel specific

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to IPC4_INTEL_MIC_PRIVACY_CAPS_HW_CFG. I don't think other vendors will have MICPVCP register in their SoC.

src/audio/base_fw.c Outdated Show resolved Hide resolved
src/audio/copier/copier_generic.c Outdated Show resolved Hide resolved
src/audio/copier/copier_hifi.c Outdated Show resolved Hide resolved
app/boards/intel_adsp_ace30_ptl.conf Show resolved Hide resolved
src/audio/copier/copier.c Outdated Show resolved Hide resolved
src/audio/copier/copier.c Outdated Show resolved Hide resolved
src/audio/mic_privacy_manager/mic_privacy_manager.c Outdated Show resolved Hide resolved
src/audio/mic_privacy_manager/mic_privacy_manager.c Outdated Show resolved Hide resolved
return mic_privacy_api->get_dma_data_zeroing_link_select();
}
//hardcoded for FW_MANAGED
return 0xFFFFFFFF;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~0

return 0xFFFFFFFF;
}

struct mic_privacy_settings fill_mic_priv_settings(uint32_t mic_disable_status)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think supplying a structure to be filled as a parameter is preferred over returning one

src/audio/mic_privacy_manager/mic_privacy_manager.c Outdated Show resolved Hide resolved
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbukowsk can you confirm a high level overview of how it works when FW managed. i.e. I assume FW will send an IPC to SW when the mute is enabled/disabled ? What about Mic state at FW boot ?

src/audio/mic_privacy_manager/mic_privacy_manager.c Outdated Show resolved Hide resolved
src/audio/mic_privacy_manager/mic_privacy_manager.c Outdated Show resolved Hide resolved
src/include/sof/audio/mic_privacy_manager.h Outdated Show resolved Hide resolved
#include <ipc4/base-config.h>
#include "../audio/copier/copier_gain.h"

#define ADSP_RTC_FREQUENCY 32768
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in Zephyr as its HW specific.

src/include/sof/audio/mic_privacy_manager.h Outdated Show resolved Hide resolved
Comment on lines 57 to 83
int mic_privacy_manager_init(void);

int mic_privacy_manager_get_policy(void);

uint32_t mic_privacy_get_policy_register(void);

void enable_fw_managed_irq(bool enable_irq);

void enable_dmic_irq(bool enable_irq);

void handle_dmic_interrupt(void * const self, int a, int b);

void handle_fw_managed_interrupt(void * const dev);

void propagate_privacy_settings(struct mic_privacy_settings *mic_privacy_settings);

uint32_t get_dma_zeroing_wait_time(void);

uint32_t get_privacy_mask(void);

struct mic_privacy_settings fill_mic_priv_settings(uint32_t mic_disable_status);

void set_gtw_mic_state(struct mic_privacy_data *mic_priv_data, uint32_t mic_disable_status);

void update_gtw_mic_state(struct mic_privacy_data *mic_priv_data, uint32_t hw_mic_disable_status);

void mic_privacy_process(struct comp_dev *dev, struct mic_privacy_data *mic_priv, struct comp_buffer *buffer, uint32_t copy_samples);

void mic_priv_gain_input(uint8_t *buff, uint32_t buff_size, uint32_t mic_priv_state,
const struct ipc4_audio_format *in_fmt);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are all for client usage of Mic privacy then they should all share the same mic_privacy_ prefix.

src/lib/dma.c Outdated Show resolved Hide resolved
xtos/include/sof/lib/dma.h Outdated Show resolved Hide resolved
src/audio/base_fw.c Outdated Show resolved Hide resolved
Copy link
Contributor

@jsarha jsarha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No bugs from me (the others already found the serious stuff), but couple of suggestions more.

src/audio/copier/copier_dai.c Outdated Show resolved Hide resolved
src/lib/dma.c Outdated Show resolved Hide resolved
src/include/ipc4/base_fw.h Outdated Show resolved Hide resolved
@abonislawski abonislawski force-pushed the mbukowsk-mic_privacy branch 6 times, most recently from 70c6211 to 37336ba Compare February 8, 2025 16:32
src/audio/copier/copier.c Outdated Show resolved Hide resolved
@lgirdwood
Copy link
Member

@mbukowsk can you check CI, several failures. Thanks !

Copy link
Contributor

@ujfalusi ujfalusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbukowsk, the privacy_capabilities is configured to the wrong struct, that is going to case the host quite a bit of issues as it will not find it in hw_config and there will be two entries with the same ID in fw_config.

src/audio/copier/copier_gain.c Outdated Show resolved Hide resolved
src/audio/copier/copier_gain.h Outdated Show resolved Hide resolved
src/audio/base_fw.c Outdated Show resolved Hide resolved
@@ -51,6 +54,10 @@ SOF_DEFINE_REG_UUID(copier);

DECLARE_TR_CTX(copier_comp_tr, SOF_UUID(copier_uuid), LOG_LEVEL_INFO);

#if CONFIG_MICROPHONE_PRIVACY
static int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you add the mic_privacy_configure() so that forward declaration is not needed?
Plus:

#else
static inline int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd) { return 0 }
#endif /* CONFIG_MICROPHONE_PRIVACY */

and you can save on the ifdefs in code

@@ -131,6 +138,15 @@ static int copier_init(struct processing_module *mod)
comp_err(dev, "unable to create host");
goto error;
}
#if CONFIG_MICROPHONE_PRIVACY
if (cd->direction == SOF_IPC_STREAM_CAPTURE && node_id.f.dma_type == ipc4_hda_host_output_class) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

123 chars long..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still 123 long.

@@ -27,7 +30,7 @@ int copier_gain_set_params(struct comp_dev *dev, struct copier_gain_params *gain
/* Set basic gain parameters */
copier_gain_set_basic_params(dev, gain_params, ipc4_cfg);

switch (dd->dai->type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did this compiled before this patch?
I cannot see dd anywhere in the change,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and if there were dd to begin with, then why we don't we take the pointers out from it locally?

* @return 0 on success, negative error code on failure.
*/
int copier_gain_set_params(struct comp_dev *dev, struct copier_gain_params *gain_params, uint32_t fade_period);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no dd was here either

struct ipc4_copier_module_cfg *copier_cfg = cd->dd[0]->dai_spec_config;
const int channels = copier_cfg->base.audio_fmt.channels_count;

ret = copier_set_gain(dev, cd->dd[0]->gain_data, gain_data, channels);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two gain_data is a bit confusing here.

}
}

void update_gtw_mic_state(struct mic_privacy_data *mic_priv_data, uint32_t hw_mic_disable_status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I cannot see that this function is called?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still not called?

@lgirdwood
Copy link
Member

@mbukowsk, the privacy_capabilities is configured to the wrong struct, that is going to case the host quite a bit of issues as it will not find it in hw_config and there will be two entries with the same ID in fw_config.

@ujfalusi ok that's a blocker for kernel. Can you reply with what this should look like for kernel so @mbukowsk can copy.

@ujfalusi
Copy link
Contributor

ujfalusi commented Feb 11, 2025

@mbukowsk, the privacy_capabilities is configured to the wrong struct, that is going to case the host quite a bit of issues as it will not find it in hw_config and there will be two entries with the same ID in fw_config.

@ujfalusi ok that's a blocker for kernel. Can you reply with what this should look like for kernel so @mbukowsk can copy.

No, this is a blocker for this PR.

The firmware places the IPC4_PRIVACY_CAPS_HW_CFG (as is a hardware configuration tuple with ID 11) into the FW_CFG (as is firmware configuration). The ID 11 is IPC4_MAX_ASTATE_COUNT_FW_CFG in firmware config.

These are different configurations, one is queried with SOF_IPC4_FW_PARAM_FW_CONFIG (basefw param 6), the other is SOF_IPC4_FW_PARAM_HW_CONFIG_GET (basefw param 7).

The IPC4_PRIVACY_CAPS_HW_CFG must be placed to the hardware config data in basefw_hw_config() and not in basefw_config() as this PR does.

The corresponding kernel patch is thesofproject/linux@7f00cf9

int ret;

/* Set basic gain parameters */
copier_gain_set_basic_params(dev, dd, ipc4_cfg);
copier_gain_set_basic_params(dev, gain_params, ipc4_cfg);

switch (dd->dai->type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so at this patch this is not going to compile. dd is not defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for dd it looks like part of this change is placed in the next commit, I will move it to the first one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks that way, I'll wait for the update with the fix.

Change type of arguments for gain params setting functions.
DAI data struct is replaced by gain_params. Components other
than DAI can also use copier gain feature (eg. microphone privacy)

Signed-off-by: Michal Bukowski <[email protected]>
Audio privacy feature allows end user to directly
control if user space applications receive actual
data from input devices (microphones). The control
is bypassing application level settings or operating
system controls (like audio endpoint volume).

Signed-off-by: Michal Bukowski <[email protected]>
Added empty implementation which always returns success

Signed-off-by: Michal Bukowski <[email protected]>
…ANGE

SW sends this IPC when microphone privacy state is changed for
HW_MANAGED mode and SNDW interface.

Signed-off-by: Michal Bukowski <[email protected]>
Copy link
Contributor

@ujfalusi ujfalusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abonislawski , there are also valid checkpatch finds.

int ret;

/* Set basic gain parameters */
copier_gain_set_basic_params(dev, dd, ipc4_cfg);
copier_gain_set_basic_params(dev, gain_params, ipc4_cfg);

switch (dd->dai->type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks that way, I'll wait for the update with the fix.

Audio privacy feature allows end user to directly control if user space
applications receive actual data from input devices (microphones).
The control is bypassing application level settings or operating system
controls (like audio endpoint volume).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really Intel specific implementation of a microphone privacy, I think this has to be mentioned

@@ -25,6 +25,7 @@
#include <sof/debug/telemetry/performance_monitor.h>
#include <sof/debug/telemetry/telemetry.h>
#include <sof/debug/telemetry/performance_monitor.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spurious change

IPC4_UAOL_CAPS_HW_CFG = 10
IPC4_UAOL_CAPS_HW_CFG = 10,
/* Mic privacy capabilities */
IPC4_PRIVACY_CAPS_HW_CFG = 11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to IPC4_INTEL_MIC_PRIVACY_CAPS_HW_CFG. I don't think other vendors will have MICPVCP register in their SoC.


uint32_t get_dma_zeroing_wait_time(void);

uint32_t get_privacy_mask(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for these blank lines.

@@ -362,12 +363,12 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
ret = -EINVAL;
continue;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the blank line was fine.

sink, converter[j],
bytes, dd->chmap);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for blank line


LOG_MODULE_REGISTER(LOG_DOMAIN);

int mic_privacy_manager_init(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is Intel specific, can we emphasize it with file name and external API names?

mic_priv_data->mic_privacy_state = MIC_PRIV_MUTED;
} else {
mic_priv_data->mic_privacy_state = MIC_PRIV_UNMUTED;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what is the coding style in SOF now-days, but this patch uses two style when there is a single instruction in the if/else
Zephyr demands curly brackets always, like this. We used to be following the kernel's with no need for them.

}
}

void update_gtw_mic_state(struct mic_privacy_data *mic_priv_data, uint32_t hw_mic_disable_status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still not called?

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abonislawski some high level questions.

  1. In HW managed - FW gets IRQ from HW and mutes. Does it send IPC to SW to inform ?
  2. In FW managed mode - How does FW know when to mute - is it relying on SW to send an IPC ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants